<?php

namespace api\test\controller;

use cmf\controller\RestBaseController;

class UploadController extends RestBaseController
{
    public function upload()
    {
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file('file');
        // 移动到框架应用根目录/public/uploads/images 目录下
        if ($file) {
            $info = $file->validate(['size'=>1024 * 1024 * 3,'ext'=>'jpg,png'] )->move(CMF_ROOT . 'public/uploads/images/');
            if ($info) {
                $this->success('上传成功',[
                    'src' => config('test.url').'uploads/images/' . $info->getSaveName()
                ]);

            } else {
                $this->error($file->getError());
            }
        }
    }
}